package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.SysCompanyControllerApi;
import com.nineclock.message.dto.SysApplyJoinCompanyUserDTO;
import com.nineclock.system.dto.SysAllowedJoinCompanyUserDTO;
import com.nineclock.system.dto.SysChangeMainManagerDTO;
import com.nineclock.system.dto.SysCompanyDTO;
import com.nineclock.system.dto.SysCompanyUserDTO;
import com.nineclock.system.service.SysCompanyUserService;
import com.nineclock.system.service.SyscompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;


@RestController
@RequestMapping("/company")
public class SysCompanyController implements SysCompanyControllerApi {
    @Autowired
    SyscompanyService syscompanyService;
    @Autowired
    SysCompanyUserService sysCompanyUserService;


    @Override
    @GetMapping
    public Result<SysCompanyDTO> queryCompanyInfo() {
        SysCompanyDTO sysCompanyDTO = syscompanyService.queryCompanyInfo();
        return Result.success(sysCompanyDTO);
    }

    @Override
    @PostMapping("/uploadOSS")
    public Result<String> uploadOSS(MultipartFile file) throws IOException {
        String imgPath = syscompanyService.uploadOSS(file);
        return Result.success(imgPath);
    }

    @Override
    @PutMapping
    public Result updateCompanyInfo(@RequestBody SysCompanyDTO sysCompanyDTO) {
        syscompanyService.updateCompanyInfo(sysCompanyDTO);
        return Result.success();
    }

    @Override
    @GetMapping("/getCurrentAdmin")
    public Result<SysCompanyUserDTO> getCurrentAdmin() {
        SysCompanyUserDTO sysCompanyUserDTO = sysCompanyUserService.getCurrentAdmin();
        return Result.success(sysCompanyUserDTO);
    }

    @Override
    @PostMapping("/config/admin")
    public Result changeSysAdmin(@RequestBody SysChangeMainManagerDTO sysChangeMainManagerDTO) {
        syscompanyService.changeSysAdmin(sysChangeMainManagerDTO);
        return Result.success();
    }

    @Override
    @GetMapping("/list")
    public Result<List<SysCompanyDTO>> queryCompanyByName(String keyword) {
        List<SysCompanyDTO> companyDTOList = syscompanyService.queryCompanyByName(keyword);
        return Result.success(companyDTOList);
    }

    @Override
    @PostMapping("/applyJoinCompany")
    public Result applyJoinCompany(@RequestBody SysApplyJoinCompanyUserDTO sysApplyJoinCompanyUserDTO) {
        syscompanyService.applyJoinCompany(sysApplyJoinCompanyUserDTO);
        return Result.success();
    }

    @Override
    @PostMapping("/allowedJoinCompany")
    public Result allowedJoinCompany(SysAllowedJoinCompanyUserDTO sysAllowedJoinCompanyUserDTO) {
        sysCompanyUserService.allowedJoinCompany(sysAllowedJoinCompanyUserDTO);
        return Result.success();
    }
}
